package me.boot.web.common.template.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.base.utils.ReflectUtil;
import me.boot.db.mybatis.template.entity.AutoEntity;
import me.boot.db.mybatis.utils.MpUtils;

/**
 * @Description:
 * @author: Sylar
 * @date: 2021年11月19日 11:07 上午
 */
public abstract class BaseNestedEntity<T extends AutoEntity> extends AutoEntity {

    @TableField(exist = false)
    protected Class<T> entityClass;

    protected BaseMapper<T> getMapper() {
        return MpUtils.getMapper(getEntityClass());
    }

    protected Class<T> getEntityClass() {
        if (entityClass == null) {
            this.entityClass = ReflectUtil.getGenericType(this.getClass(), 0);
        }
        return entityClass;
    }
}
